package com.hnas.trade.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.trade.dao.AbnormalOrderDao;
import com.hnas.trade.orm.AbnormalOrder;

@Component("abnormalOrderDao")
public class AbnormalOrderDaoImpl extends BaseDaoImpl<AbnormalOrder> implements AbnormalOrderDao{

	public AbnormalOrderDaoImpl() {
		super(AbnormalOrder.class);
	}

	@Override
	public AbnormalOrder saveOrUpdate(AbnormalOrder vo) throws Exception {
		AbnormalOrder record = this.entityManager.find(AbnormalOrder.class, vo.getId());
		if(record == null){
			record = new AbnormalOrder();
			BeanUtils.copyProperties(record, vo);
			this.entityManager.persist(record);
		}else{
			BeanUtils.copyProperties(record, vo);
			this.entityManager.merge(record);
		}
		return record;
	}

	@Override
	public List<String> findAllAbnormalTranSnoByDate(String startDate, String endDate) {
		String begin = startDate+" 00:00:00";
		String end = endDate+" 23:59:59";
		String sql = "select trade_sno from m_base_wxxnk_abnormal_order where trade_end_time BETWEEN str_to_date('"+begin+"','%Y%m%d %H:%i:%s') AND str_to_date('"+end+"','%Y%m%d %H:%i:%s')";
		Query query = this.entityManager.createNativeQuery(sql);
		return query.getResultList();
	}

}
